﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.EventService.Configuration;
using System.Threading;

namespace A2DFramework.EventService.DistributeEventBus
{
    public class DistributeEventBusProvider : IEventBusProvider
    {
        private static EventBusClientBrokerRunner runner;
        public DistributeEventBusProvider()
        {
            runner = new EventBusClientBrokerRunner(EventServiceConfiguration.EventServer.Address, EventServiceConfiguration.EventServer.Port, EventServiceConfiguration.Identifier, "", EventServiceConfiguration.RetryConnectInterval);
            ThreadStart ths = new ThreadStart(runner.On);
            Thread thd = new Thread(ths);
            thd.Start();
        }

        public void Emit(IEventBase evt)
        {
            runner.Publish(evt);
        }

        public void Emit<T>(T evt) where T : IEventBase
        {
            runner.Publish<T>(evt);
        }
    }
}
